package com.ruoyi.process.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.process.constant.VariablesConstants;
import com.ruoyi.process.domain.workflow.FormDTO;
import com.ruoyi.process.service.FlowServiceFactory;
import com.ruoyi.process.service.IFlowInstance;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class FlowInstanceImpl extends FlowServiceFactory implements IFlowInstance {

    @Override
    public String startFlow(FormDTO form) {

        // 1. 设置变量
        Map<String, Object> variables = new HashMap<>(); // 请求中的
        variables.put(VariablesConstants.INITIATOR,1);// SecurityUtils.getUserId()); // 设置额外的，便于后期处理获取
       // 2.业务数据插入,带businessKey
        form.setProcessId("flow_myjqgvmc");
        form.setBusinessKey("order-test-001");
//        String businessKey ="test123";

        // 3. 启动流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(form.getProcessId(), form.getBusinessKey(), variables);


        return processInstance.getProcessInstanceId();
    }

    @Override
    public String revoke(FormDTO form) {
        return null;
    }

    @Override
    public int deleteFlowInstanceByIds(Long[] ids) {
        return 0;
    }
}
